﻿using System;

namespace Boggle {

    /// <summary>
    /// Represents a particular Die used by the Böggle board.
    /// <BR>
    /// Author: David I. Schwartz (dis@mail.rit.edu)
    /// <BR>
    /// </summary>
    public class Die {

        private string letters;      // letters on the Die
        private int sides;           // number of sides of Die
        private string currentSide;  // current side showing

        /// <summary>
        /// Construct a Die.
        /// </summary>
        /// <param name="letters">letters on each Die side</param>
        /// <param name="sides">number of Die sides</param>
        public Die(string letters, int sides) {
            this.sides = sides;
            this.letters = letters;
            reset(); // show blank
        }

        /// <summary>
        /// Set the sides of Die.
        /// </summary>
        public int Sides {
            set { sides = value; }
        }
        
        /// <summary>
        /// Roll the Die to pick a random letter. 
        /// Automatically appends a "u" for "Q".
        /// </summary>
        /// <returns>the random letter</returns>
        public string roll() {
            int sideNumber = new Random().Next(0, sides);
            currentSide = letters[sideNumber].ToString();
            if (currentSide == "Q") 
                currentSide += "u";
            return currentSide;
        }
        
        /// <summary>
        /// Do not show any side of the Die.
        /// </summary>
        public void reset() {
            currentSide = "";
        }

        /// <summary>
        /// Return current side of Die.
        /// </summary>
        public string CurrentSide {
            get { return currentSide; } 
        }

        /// <summary>
        /// Stringify the current Die by showing all sides.
        /// </summary>
        /// <returns>All letters</returns>
        public override string ToString() {
            return letters;
        }

    } // class Die

} // Boggle
